package com.xinqi.modules.homework.homework.controller.inner;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.StudentOperateGroup;
import com.xinqi.common.core.enums.StudentSwitchType;
import com.xinqi.modules.homework.homework.dto.req.CourseHomeworkStudentDetailDTO;
import com.xinqi.modules.homework.homework.dto.req.CourseHomeworkUpdateDTO;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkResultDTO;
import com.xinqi.modules.homework.homework.service.CourseHomeworkService;
import com.xinqi.modules.homework.homework.service.CourseHomeworkSyncService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/inner/homework")
@RequiredArgsConstructor
public class HomeWorkInnerController {

    private final CourseHomeworkService courseHomeworkService;

    private final CourseHomeworkSyncService courseHomeworkSyncService;

    @GetMapping(value = "/timing")
    public R<String> timingRun() {
        courseHomeworkService.homeworkTiming();
        return R.ok("作业定时发布已执行");
    }

    @PostMapping(value = "/student-operate-group")
    public R<String> studentOperateGroup(Long classId, Long studentId, Long groupId, StudentOperateGroup operateGroup) {
        courseHomeworkSyncService.studentOperateGroup(classId, studentId, groupId, operateGroup);
        return R.ok("成员进组退组操作已记录");
    }

    /**
     * 学生加入班级 -- 作业同步
     */
    @PostMapping("/student-join-class")
    public R<Void> studentJoinClass(Long classId, Long studentId) {
        courseHomeworkSyncService.studentJoinClass(classId, studentId);
        return R.ok();
    }

    /**
     * 学生身份转换 -- 作业同步
     */
    @PostMapping("/student-identity-switch")
    public R<Void> studentIdentitySwitch(Long classId, Long studentId, StudentSwitchType switchType) {
        courseHomeworkSyncService.studentIdentitySwitch(classId, studentId, switchType);
        return R.ok();
    }

    /**
     * 查询课程栏目作业-详情
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/{id}")
    public R<CourseHomeworkResultDTO> findById(@PathVariable("id") Long id, CourseHomeworkStudentDetailDTO dto) {
        return R.data(courseHomeworkService.findById(id, dto));
    }

    /**
     * 修改课程栏目作业信息
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/{id}")
    public R<String> update(@PathVariable("id") Long id, @RequestBody CourseHomeworkUpdateDTO dto) {
        dto.setId(id);
        courseHomeworkService.updateById(dto);
        return R.data("更新成功");
    }
}
